package com.atguigu.gmall.alipay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.*;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 李旭
 * @create: 2021-09-14 15:24
 *
 *    SDK
 *
 *    微信 SDK   开发工具包
 **/
public class AlipayDemo {


    //调用统一收单下单并支付页面接口
    public static void main(String[] args) throws AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipaydev.com/gateway.do",
                "2016102100732915",
                "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDcDMGGfsLI9fg8hkODHiUKxPyAfyTAdZ0DfqbXQIrCrtndyF36bBxEEF9KNjBSE8B/nP1as4vB4f46o3GEX1cFm5uBrIBh7m2pGr71N0iYWoEqEby5A28fy+V9RXkTZnJQBAzBh7cZlMtKMvfqRkDEMsTAuhOvVv9ciC5qvEkGMh8HO7TOJnH87+WsxdcSuCbchGFAOSUVW54F6b9hFSNljs51PfQdHVMd+PNZcxz266k6xGEjKVIlOXykV/U/MAb10dBpIMog90DyeleYDRcmbZK6GLz5/F+3yZXgoKjbMb2kPj1CFrWbF6sg0ngwYGYRKJ+80CMrTlpIZFCDzH/7AgMBAAECggEAdFGd3w2Uw4waG0xR1baSmB3G59nNwJqrVBSX9wLcFss8yVrIKr8JNgV9iYoZgtmEETEYT+DHCMcAj1ikgfev1XwK+MIJ3zqc5x4HQTJnAnoc+vMDUr14+VLbzZtyxAmMdbWeVJL7+97Gk0Nb/5ABXnUDwmjaTP5s4Cnwd2VuKIJM9JyJikGSOVqxRuILAhk6hbQSJbdWrlOvfSF+ilBjVnV03bD/wAeYxnSM1ZHo0ot7S2/G7roIe4UuDtp3Xg8e7U9iG6fe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RqydMBfRsB4V9aHUH0KCV875mzF7Feh3VoDilcDpGtuKo5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",
                "RSA2"

        );
        //统一收单下单并支付页面接口
      /*  AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        ////////////////////////
        AlipayTradePagePayModel model = new AlipayTradePagePayModel();
        model.setOutTradeNo("ATGUIGU2134425436432765");
        model.setTotalAmount("88.88");
        model.setSubject("Iphone12 16G");
        model.setProductCode("FAST_INSTANT_TRADE_PAY");
        model.setBody("Iphone12 16G");
        model.setQrPayMode("1");
        model.setQrcodeWidth(100L);*/
      //退款
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        AlipayTradeRefundModel model = new AlipayTradeRefundModel();
        model.setOutTradeNo("20150320010101001");
        model.setRefundAmount("57777");
        request.setBizModel(model);

        AlipayTradeRefundResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());
        //发出
        System.out.println(response.getBody());
        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }
}
